package com.hzhr.iot.huaweiiot.constant;

import com.hzhr.iot.core.constant.HttpExceptionCategory;
import com.hzhr.iot.core.constant.ServiceErrors;
import com.hzhr.iot.core.constant.ServiceExceptionCategory;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;

public enum Huaweiiot_ErrorsEnum implements ServiceErrors {
    //region DeviceService
    //region addDevice
    DEVICESERVICE_ADD_DEVICE_201(201, "在华为iot平台新增设备台账", "华为iot平台服务调用错误", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN),
    //endregion
    //region edit
    DEVICESERVICE_EDIT_DEVICE_201(201, "在华为iot平台修改设备台账", "华为iot平台服务调用错误", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN),
    //endregion
    //endregion

    //region HuaweiiotService
    //region registerDevice
    HUAWEIIOTSERVICE_REGISTER_DEVICE_201(201, "在华为iot平台上注册设备", "华为iot平台服务调用错误", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN),
    //endregion
    //region postDeviceCommand
    HUAWEIIOTSERVICE_POST_COMMAND_201(201, "向华为iot平台的指定设备发送命令", "华为iot平台服务调用错误", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN),
    HUAWEIIOTSERVICE_POST_COMMAND_202(202, "向华为iot平台的指定设备发送命令", "获取northApiClient失败", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN),
    //endregion
    //region editDevice
    HUAWEIIOTSERVICE_EDIT_DEVICE_201(201, "在华为iot平台上编辑设备", "华为iot平台服务调用错误", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN),
    //endregion
    //region deleteDevice
    HUAWEIIOTSERVICE_DELETE_DEVICE_201(201, "在华为iot平台上删除设备", "华为iot平台服务调用错误", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN),
    //endregion
    //region getNorthApiClient
    HUAWEIIOTSERVICE_GET_NORTH_API_CLIENT_201(201, "获取northApiClient", "华为iot平台服务调用错误", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN),
    //endregion
    //region getTokenDto
    HUAWEIIOTSERVICE_GET_TOKEN_DTO_201(201, "获取tokenDto", "华为iot平台服务调用错误", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN),
    HUAWEIIOTSERVICE_GET_TOKEN_DTO_202(202, "获取tokenDto", "获取northApiClient失败", ServiceExceptionCategory.BUSINESS_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.FORBIDDEN);

    //endregion
    //endregion

    private Integer code;
    private String messaeg;
    private String business;
    private ServiceExceptionCategory serviceExceptionCategory;
    private HttpExceptionCategory httpExceptionCategory;
    private HttpStatus httpStatus;
    Huaweiiot_ErrorsEnum(Integer code, String business, String message, ServiceExceptionCategory serviceExceptionCategory, HttpExceptionCategory httpExceptionCategory, HttpStatus httpStatus) {
        this.code = code;
        this.business = business;
        this.messaeg = message;
        this.serviceExceptionCategory = serviceExceptionCategory;
        this.httpExceptionCategory = httpExceptionCategory;
        this.httpStatus = httpStatus;
    }
    @Override
    public Integer getCode() {
        return code;
    }
    @Override
    public String getBusiness() {
        return business;
    }
    @Override
    public String getMessage() {
        return messaeg;
    }
    @Override
    public ServiceExceptionCategory getServiceExceptionCategory() {
        return serviceExceptionCategory;
    }
    @Override
    public HttpExceptionCategory getHttpExceptionCategory() {
        return httpExceptionCategory;
    }
    @Override
    public HttpStatus getHttpStatus() {
        return httpStatus;
    }
    @Override
    public void setMessage(String message) {
        this.messaeg = message;
    }

    public static Huaweiiot_ErrorsEnum getEnumByName(String name) {
        if (StringUtils.isEmpty(name)) return null;
        for (Huaweiiot_ErrorsEnum errorsEnum : Huaweiiot_ErrorsEnum.values()) {
            if (errorsEnum.name().equals(name)) {
                return errorsEnum;
            }
        }
        return null;
    }
}
